package cn.tedu.mall.book.web;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 通用支持分页查询的结果对象类型
 * @author zxjun
 * @date 2022/6/29 11:23
 */
@Data
public class JsonPage<T> implements Serializable {
    @ApiModelProperty(value = "当前页码",name = "pageNum")
    private Integer pageNum;
    @ApiModelProperty(value = "每页条数",name = "pageNum")
    private Integer pageSize;
    @ApiModelProperty(value = "总条数",name = "pageNum")
    private Long totalCount;
    @ApiModelProperty(value = "总页数",name = "pageNum")
    private Integer totalPages;
    private List<T> list;

    public static <T> JsonPage<T> restPage(PageInfo<T> pageInfo){
        JsonPage<T> result = new JsonPage<>();
        result.setPageNum(pageInfo.getPageNum());
        result.setPageSize(pageInfo.getPageSize());
        result.setTotalCount(pageInfo.getTotal());
        result.setTotalPages(pageInfo.getPages());
        result.setList(pageInfo.getList());
        return result;
    }
}
